﻿package mortal.game.view.copy.wine.view
{
    import Message.Game.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class WinePartyMoraWin extends BaseWindow
    {
        private var _bg:GImageBitmap;
        private var _polic:WinePartyMoraSpr;
        private var _meinv:WinePartyMoraSpr;
        private var _womenFucker:WinePartyMoraSpr;
        private var _selLeftTime:GTextFiled;
        private var _leftTime:SecTimerView;
        private var _moraArr:Array;
        private static var _instance:WinePartyMoraWin;

        public function WinePartyMoraWin(param1:ILayer = null)
        {
            this._moraArr = [];
            super(param1);
            setSize(490, 300 + 15 + 20);
            title = Language.getString(41018);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            _isAddClolseButton = false;
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.WinePartyMoraBg, 0 + 5, 0 + 32, this);
            this._polic = UICompomentPool.getUICompoment(WinePartyMoraSpr);
            this._polic.x = 6;
            this._polic.y = 33;
            this._polic.bgName = ImagesConst.WinePartyPolice;
            this._polic.moraType = EWineMoraType._EMoraTypePaper;
            this._polic.moraName = Language.getString(41019);
            this.addChild(this._polic);
            this._moraArr.push(this._polic);
            this._meinv = UICompomentPool.getUICompoment(WinePartyMoraSpr);
            this._meinv.x = 247;
            this._meinv.y = 33;
            this._meinv.bgName = ImagesConst.WinePartyMeinv;
            this._meinv.moraType = EWineMoraType._EMoraTypeScissor;
            this._meinv.moraName = Language.getString(41020);
            this.addChild(this._meinv);
            this._moraArr.push(this._meinv);
            this._womenFucker = UICompomentPool.getUICompoment(WinePartyMoraSpr);
            this._womenFucker.x = 6;
            this._womenFucker.y = 175;
            this._womenFucker.bgName = ImagesConst.WinePartyFuckWomener;
            this._womenFucker.moraType = EWineMoraType._EMoraTypeRock;
            this._womenFucker.moraName = Language.getString(41021);
            this.addChild(this._womenFucker);
            this._moraArr.push(this._womenFucker);
            this._selLeftTime = UIFactory.gTextField(Language.getString(41022), 180, 320 - 5, 80, 22, this, GlobalStyle.textFormatPutong.setSize(13));
            this._leftTime = UIFactory.secTimeView("s", 260, 320 - 4, 125, 22, this, GlobalStyle.textFormatHong.setSize(13));
            this._polic.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._meinv.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._womenFucker.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_4:WinePartyMoraSpr = null;
            var _loc_2:* = event.target as WinePartyMoraSpr;
            for each (_loc_4 in this._moraArr)
            {
                
                if (_loc_4 == _loc_2)
                {
                    _loc_4.isSelect = true;
                    _loc_3 = _loc_4.moraType;
                }
                else
                {
                    _loc_4.isSelect = false;
                }
                _loc_4.mouseEnabled = false;
                if (this._leftTime.running)
                {
                    this._leftTime.stop();
                    this._selLeftTime.visible = false;
                    this._leftTime.visible = false;
                }
            }
            this.sendMoraResult(_loc_3);
            return;
        }// end function

        override public function stageResize() : void
        {
            x = (Global.stage.stageWidth - this.width) / 2;
            y = (Global.stage.stageHeight - this.width) / 2;
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.stageResize();
            this._leftTime.setLeftTime(5);
            this._leftTime.timeOutHandler = this.timeOutHandler;
            return;
        }// end function

        private function timeOutHandler() : void
        {
            var _loc_3:WinePartyMoraSpr = null;
            var _loc_1:* = Math.random() * 3;
            var _loc_2:* = this._moraArr[_loc_1] as WinePartyMoraSpr;
            _loc_2.isSelect = true;
            for each (_loc_3 in this._moraArr)
            {
                
                _loc_3.mouseEnabled = false;
            }
            this._selLeftTime.visible = false;
            this._leftTime.visible = false;
            this.sendMoraResult(_loc_2.moraType);
            this.hide();
            return;
        }// end function

        private function sendMoraResult(param1:int) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WinePartySendMoraType, param1));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._bg.dispose();
            this._bg = null;
            this._polic.dispose();
            this._polic = null;
            this._meinv.dispose();
            this._meinv = null;
            this._womenFucker.dispose();
            this._womenFucker = null;
            this._leftTime.dispose();
            this._leftTime = null;
            this._selLeftTime.dispose();
            this._selLeftTime = null;
            this._moraArr.length = 0;
            return;
        }// end function

        public static function get instance() : WinePartyMoraWin
        {
            if (_instance == null)
            {
                _instance = new WinePartyMoraWin;
            }
            return _instance;
        }// end function

    }
}
